<?php

/**
 * Project filter form base class.
 *
 * @package    maximous
 * @subpackage filter
 * @author     Mina.Gerges.Wadea
 * @version    SVN: $Id: sfDoctrineFormFilterBaseTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
abstract class BaseFormFilterDoctrine extends sfFormFilterDoctrine
{

    public function setup()
    {
        
    }

    /**
     * check if tha login user can controle the statues field or need_check fild 
     */
    public function configureLoginUserRoleOnChangeStatusAndNeedCheck()
    {
        $maxUser = $this->getOption('maxUser');
        if (!$maxUser instanceof MaxUser)
        {
            throw new InvalidArgumentException('to use checkLoginUserRoleOnChangeStatusAndNeedCheck() you need to set maxUser object in form options');
        }
        // check if user can change statues 
        if ($maxUser->getMaxUserRole()->canChangeStatus())
        {
            $class     = $this->getModelName();
            $modelName = new $class;
            $statues   = $modelName->getStatuesArray();
            $this->setWidget('statues', new sfWidgetFormChoice(array('choices' => array_merge(array('' => 'all'), $statues))));
            $this->setValidator('statues', new sfValidatorChoice(array('choices'  => array_keys($statues), 'required' => false)));
        }
        else
        {
            unset($this['statues']);
        }

        // check if user can change statues 
        if (isset($this['need_check']))
        {
            if ($maxUser->getMaxUserRole()->canCheck())
            {
                $this->setWidget('need_check', new sfWidgetFormChoice(array('choices' => array('' => 'all', 1  => 'yes', 0  => 'no'))));
            }
            else
            {
                unset($this['need_check']);
            }
        }
    }

}
